<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );


/**
 * @package		Joomla
 * @subpackage	JobBoard
 */
class JobBoardTableJA_Email extends JTable
{
	/** @var int Primary key */
	var $id				= null;
	
	var $subscription_id	= null;
	
	var $paymentconfig_id	= null;
	
	var $creator	= null;
	
	/** @var string */					
	var $name 			= null;
	var $title 			= null;
	/** @var string */
	var $subject		= null;
	
	var $group 			= null;
	/** @var string */  
	var $content		= null;
	/** @var string */ 
	var $EmailFromAddress		= null;
	var $EmailFromName		= null;
	/** @var string */  
	var $published		= null;
	/** @var string */  
	var $checked_out		= null;
	/** @var string */  
	var $checked_out_time	= null;
	
	var $language	= null;
	var $modified = 0;
	
	var $system = 0;
	
	var $update_date = null;
	/**
	* @param database A database connector object
	*/
	function __construct(&$db)
	{
		parent::__construct( '#__ja_email', 'id', $db );		
	}
	
	/**
	 * Overloaded check function
	 *
	 * @access public
	 * @return boolean
	 * @see JTable::check
	 * @since 1.5
	 */
	function check()
	{		
//		JFilterOutput::objectHTMLSafe($this,ENT_QUOTES,'');
		$filter	= new JFilterInput( '', '', 1, 1);
		$this->title = $filter->clean($this->title);
		$this->content = $filter->clean($this->content);
		$this->subject = $filter->clean($this->subject);
		if(empty($this->name))
			return JText::_('Name must not be empty');
			
		if(empty($this->subject))
			return JText::_('Subject must not be empty');
					
		$where = '';
		
		
		$lang = JRequest::getVar('filter_lang');
		if($lang) $where .= " and language='$lang'";
		
		$subscription_id = JRequest::getInt('subscription_id');
		$paymentconfig_id = JRequest::getInt('paymentconfig_id');
		if($subscription_id) $where .= " and subscription_id='$subscription_id'";
		if($paymentconfig_id) $where .= " and paymentconfig_id='$paymentconfig_id'";
		
		$query = "SELECT * FROM #__ja_email WHERE upper(name) = upper('".$this->name."')".$where;

		$db = &JFactory::getDBO();
		$db->setQuery($query);
				
		$result = $db->loadObjectList();
		
		if((count($result) >0)&&(empty($this->id))){
			JError::raiseWarning(1, JText::_("Email name already exist."))	;
			return false;
		}
				
		return true;
	}
	function load($key)
	{
		parent::load($key);
//		$this->title = JFilterInput::_decode($this->title);
//		$this->title = JFilterInput::clean($this->title);
//		$this->subject = JFilterInput::_decode($this->subject);
//		$this->subject = JFilterInput::clean($this->subject);
//		$this->content = JFilterInput::_decode($this->content);
		return $this;
	}
}